<template>
  <div class="form-widget form-custom-son-table">
    <x-proxy-form-item
      :isInTable="widget.isInTable"
      :showRequired="showRequired"
      :label="widget.label"
      :validatorRules="validatorRules"
      :validateKey="validateKey"
      :validateInfo="validateInfo"
    >
      <div class="parameterPageMobileEmergency">
        <div class="list">

          <ul class="item">
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">标题</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('标题')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">流程编号</span></div>
                <div style="width: 75%">
                  <span
                    class="item-single-value">{{formData[getUuidByName('流程编号')]}}</span>
                </div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">申请公司</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('申请公司')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">申请部门</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{ formData[getUuidByName('申请部门')][0].name}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">申请人</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('申请人')][0].username}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">申请时间</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('申请时间')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">发货仓库</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('发货仓库')]?
                    dictMap['YORN'][formData[getUuidByName('发货仓库')][0]] : ''}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">操作人员及安保人员知会</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">
                    {{ emergencyname}}
                  </span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">合同编号</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{
                      formData[getUuidByName('合同编号')][0].name
                    }}</span></div>
              </div>
            </li>

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">申请内容</span></div>
                <div style="width: 75%">
                  <div class="item-single-value">
                   <span style="margin-right: 20px !important;"> {{formData[getUuidByName('申请内容')] }}</span>
                  </div></div>
              </div>
            </li>

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">附件</span></div>
                <div style="width: 75%">
                    <span class="item-single-value" v-for="item in formData[getUuidByName('附件')]" >
                   <div class="file-single">
                      <img :src="require('../../../../../../assets/'+  matchType(item.fileName)  +'.png')"
                           style="width: 16px;
                         height: 16px;
                      ">{{item.fileName}}</div>

                   <div style="
                       padding: 5px 5px 5px 5px;
                       width: 40px;
                       border-radius: 5px;
                       box-shadow: 0 1px 8px rgba(0,0,0,0.3);
                       margin-top: 5px;
                       vertical-align: middle;
                      text-align: center;
                      ">
                     <a style="
                           color: rgb(19, 19, 19);
                           border: 1px solid rgb(242, 242, 242);
                           margin-top: 10px;
                           border-radius: 6px;
                           background: rgb(255, 255, 255);
                    " @click="downloadFileEmergency(item)">下载</a></div>
                 </span>
                </div>
              </div>
            </li>


          </ul>
        </div>
      </div>
    </x-proxy-form-item>
  </div>
</template>

<script>
import FormWidgetConfigMixin from '@/mixin/form-widget.mixin'

export default {
  name: 'EmergencyShipmentRead',
  mixins: [FormWidgetConfigMixin],
  components: {},
  data: function () {
    return {
      mainData:{},
      dictMap:{
        'YORN':{
          'ZH':'珠海',
          'CZ':'常州'
        }
      },
      emergencyname:'',
      childrenData: []
    }
  },
  computed: {},
  created() {
    this.getDataEmergency()
  },
  methods: {
    getDownloadUrlEmergency(url){
      const {$store, $base64} = this;
      const tenantId = $store?.state?.tenantModule?.currentOrg?.id;
      const token = $store?.state?.authModule?.token;
      const tokenBase64 = $base64.encode(
        JSON.stringify({
          xdaptenantid: tenantId,
          xdaptoken: token
        })
      );
      /*return url.replace("http://apaas-dev.crcchem.com/chem-crcchem-oms","").replace("http://apaas.crcchem.com/chem-crcchem-oms","") + `&token=${tokenBase64}`*/
      return url + `&token=${tokenBase64}`
    },
    downloadFileEmergency(item){
      let ur = this.getDownloadUrlEmergency(item.url) //url 参数 包含 file token
      let uuid = '&uuid='+this.getUuidByName('附件')
      let download = '&download=download'
      let formId = '&fromId='+this.globalData.formId
      let url = ur+download+formId+uuid
      const a = document.createElement('a'); // 创建一个HTML 元素
      a.setAttribute('download', ''); //download属性
      a.setAttribute('href', url); // href链接
      a.click(); // 自执行点击事件
    },
    getDataEmergency() {
      let result = '';
      let temp = this.formData[this.getUuidByName('操作人员及安保人员知会')]
      for (let i=0;i<temp.length;i++){
        let tempname = temp[i].username
         result += tempname+ ' ';
      }
      this.emergencyname = result
      console.log(result);
    },
    // 根据自开发组件label获取对应表单子表tableUuid
    getTableUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && value.componentType === 'FORM_WIDGET_SON_TABLE') {
          tempUuid = value.uuid
        }
      })
      return tempUuid
    },
    // 根据自开发组件label获取对应表单 子表uuid
    getChildUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && value.tableUuid) {
          tempUuid = value.uuid
        }
      })
      return tempUuid
    },

    // 根据自开发组件label获取对应表单 主表uuid
    getUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && !value.tableUuid) {
          tempUuid = value.uuid
        }
      })
      return tempUuid
    },
    matchType(fileName){
      console.log("fileName = ",fileName)
      // 后缀获取
      var suffix = '';
      // 获取类型结果
      var result = '';
      try {
        var flieArr = fileName.split('.');
        suffix = flieArr[flieArr.length - 1];
      } catch (err) {
        suffix = '';
      }
      // fileName无后缀返回 false
      if (!suffix) {
        result = false;
        return result;
      }
      // 图片格式
      var imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
      // 进行图片匹配
      result = imglist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'image';
        return result;
      };
      // 匹配txt
      var txtlist = ['txt'];
      result = txtlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'txt';
        return result;
      };
      // 匹配 excel
      var excelist = ['xls', 'xlsx'];
      result = excelist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'excel';
        return result;
      };
      // 匹配 word
      var wordlist = ['doc', 'docx'];
      result = wordlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'word';
        return result;
      };
      // 匹配 pdf
      var pdflist = ['pdf'];
      result = pdflist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'pdf';
        return result;
      };
      // 匹配 ppt
      var pptlist = ['ppt'];
      result = pptlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'ppt';
        return result;
      };
      // 匹配 视频
      var videolist = ['mp4', 'm2v', 'mkv'];
      result = videolist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'video';
        return result;
      };
      // 匹配 音频
      var radiolist = ['mp3', 'wav', 'wmv'];
      result = radiolist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'radio';
        return result;
      };
      // 匹配 压缩包
      var packagelist = ['zip', 'rar', 'tar'];
      result = packagelist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'zip';
        return result;
      };
      // 匹配 CSV
      var CSVlist = ['csv'];
      result = CSVlist.some(function (item) {
        return item == suffix;
      });
      if (result) {
        result = 'csv';
        return result;
      };
      // 其他 文件类型
      result = 'other';
      return result;
    }



  }

}
</script>

<style lang="scss">


.parameterPageMobileEmergency {
  width: 100vw;
  height: auto;
  background-color: white;

  .list {
    height: 100%;
    overflow: visible;
    padding: 0;
  }

  .item-single {
    margin: 0 !important;

  }

  .item-single-value {
    width: 100%;
    word-break: break-all;
    white-space: normal;
    margin-left: 5px;
  }

  .item-single-title {
    width: 100%;
    font-weight: 900;
    background-color: #f5a623;
    color: #fff !important;
  }

  .item {
    margin: 0;
    padding: 0;

    li {
      list-style: none;
      border: 1px solid #dcdfe6;

      span {
        padding: 8px 0 8px 0;
        color: #555;
      }

      span:first-child {
        display: inline-block;
        border-right: 1px solid #dcdfe6;
      }
    }

    li + li {
      border-top: none;
    }

    li:last-child {
      border-radius: 0 0 4px 4px
    }
  }

  .son-table {
    height: auto;
    border-top: #dcdfe6 1px solid;
    border-left: #dcdfe6 1px solid;
    border-bottom: #dcdfe6 1px solid;
    padding: 0;
    margin: 0 auto;
    margin-top: 10px;
    font-size: 12px;
    overflow: hidden;

    .th {
      color: #fff;
      border-right: 1px solid #d7d7d7;
    }
    .thv{
      color: #555555;
      border-right: 1px solid #d7d7d7;
    }
    .son-list-single {
      width: 100%;
      display: grid;
      grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 18px;
      text-align: center;
      list-style: none;
      line-height: 2.6rem;
      background-color: #f5a623;
    }

    .son-table-body {
      overflow: hidden;

      .tr {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 18px;
        text-align: center;
        list-style: none;
        line-height: 2.6rem;
        border-bottom: 1px solid #dcdfe6;
      }
    }
  }
}

</style>
